package com.it.web;

import com.it.entity.insure.AiInsureOrder;
import com.it.service.AiInsureOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.R;

import java.util.Map;

/**
 * 投保单Controller（对外暴露RESTful接口，适配前端投保流程）
 */
@RestController
@RequestMapping("/aiInsureOrder") // 接口前缀，与前端请求路径对齐
public class AiInsureOrderController {

    @Autowired
    private AiInsureOrderService aiInsureOrderService;

    /**
     * 新增投保单接口（前端步骤3“确认提交”调用）
     * @param aiInsureOrder 投保单信息（无需传递order_id）
     * @return R 新增结果（含自增order_id、保单编号）
     */
    @PostMapping("/add")
    public R addInsureOrder(@RequestBody AiInsureOrder aiInsureOrder) {
        return aiInsureOrderService.addInsureOrder(aiInsureOrder);
    }

    // 保单列表显示 模糊+分页查询
    @GetMapping("/list")
    public R list(@RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum,
                  @RequestParam(value = "pageSize",required = false,defaultValue = "5") int pageSize,
                  @RequestParam(value = "policyId",required = false) String policyId,
                  @RequestParam(value = "insuredId",required = false) String insuredId,
                  @RequestParam(value = "insuranceCoverageName",required = false) String insuranceCoverageName,
                  @RequestParam(value = "policyStatus",required = false) Integer policyStatus,
                  @RequestParam(value = "payStatus",required = false) Integer payStatus
                  ) {
        return aiInsureOrderService.list(pageNum,pageSize,policyId,insuredId,insuranceCoverageName,policyStatus,payStatus);
    }

    // 删除保单数据按id
    @DeleteMapping("/delete/{id}")
    public R deleteInsureOrder(@PathVariable("id") Integer id) {
        return aiInsureOrderService.delete(id);
    }

    // 查看详情
    @GetMapping("/get/{id}")
    public R getInsureOrder(@PathVariable("id") Integer id) {
        return aiInsureOrderService.get(id);
    }

    //修改保单状态
    @PostMapping("/updateStatus")
    public R updateStatus(@RequestBody AiInsureOrder aiInsureOrder) {
        return aiInsureOrderService.update(aiInsureOrder);
    }

    // 按保单号查询
    @GetMapping("/getOrder")
    public AiInsureOrder getOrderByPolicyId(@RequestParam(value = "policyId",required = false) String policyId){
        return aiInsureOrderService.getOrderByPolicyId(policyId);
    }

}